package com.brush.brushcommon.common;

import com.brush.brushcommon.common.sys.pojo.User;
import com.brush.brushcommon.common.sys.service.UserService;
import com.brush.brushcommon.utils.HttpUtil;
import com.brush.brushcommon.utils.JwtHelper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

public class BaseController {


    @Resource
    UserService userService;

    /**
     * 获取用户信息
     * @return
     */
    public User getUserInfo(){
        HttpServletRequest request = HttpUtil.getRequest();
        String token = request.getHeader("Authorization");
//        TODO 暂时从数据库查询 后期改为redis获取
        String userId = JwtHelper.getUserId(token);
        return userService.getById(userId);
    }


    /**
     * 获取用户手机号
     * @return
     */
    public String getUserPhone(){
        HttpServletRequest request = HttpUtil.getRequest();
        String token = request.getHeader("Authorization");
//        TODO 暂时从数据库查询 后期改为redis获取
        String userId = JwtHelper.getUserId(token);
         userService.getById(userId);
        return userService.getById(userId).getPhone();
    }



}
